/**
 * Copyright  (c) 2009-2013 XLab,  Org. 
 * All  rights  reserved. 
 */
package org.xlab.baseframework.dao.impl;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;
import org.xlab.baseframework.dao.api.ISystemLogDAO;
import org.xlab.baseframework.domain.SystemLog;
import org.xlab.baseframework.domain.query.SystemLogQueryObject;
import org.xlab.baseframework.exception.ObjectNotFoundException;
import org.xlab.baseframework.system.Declare;

/**
 * <p>
 * 系统日志DAO接口实现类
 * </p>
 * 
 * @author MaKuBEX Email:makubexnet@gmail.com
 * @version 1.0.0 Sep 7, 2010
 * @since 1.0.0
 * 
 */
@Repository
public class SystemLogDAOImpl extends BaseDAOImpl<SystemLog, Long> implements
		ISystemLogDAO {

	/**
	 * @see org.xlab.baseframework.dao.api.ISystemLogDAO#findAllByQueryObject(org.xlab.baseframework.domain.query.QueryObject)
	 */
	public List<SystemLog> findAllByQueryObject(SystemLogQueryObject queryObject)
			throws ObjectNotFoundException {
		DetachedCriteria criteria = super.generateCriteria();
		if (queryObject.getTitle() != null
				&& queryObject.getTitle().trim().length() != 0)
			criteria.add(Restrictions.like("title",
					Declare.SQL_STATEMENT_PERCENTAGE
							+ queryObject.getTitle().trim()
							+ Declare.SQL_STATEMENT_PERCENTAGE));
		if (queryObject.getContent() != null
				&& queryObject.getContent().trim().length() != 0)
			criteria.add(Restrictions.like("content",
					Declare.SQL_STATEMENT_PERCENTAGE
							+ queryObject.getContent().trim()
							+ Declare.SQL_STATEMENT_PERCENTAGE));
		if (queryObject.getCreatedBy() != null
				&& queryObject.getCreatedBy().trim().length() != 0)
			criteria.add(Restrictions.eq("createdBy", queryObject
					.getCreatedBy().trim()));
		if (queryObject.getLogType() != null)
			criteria.add(Restrictions.eq("logType", queryObject.getLogType()));
		criteria.addOrder(Order.desc(SystemLog.FIELD_CREATED_TIME));
		return super.findAllByCriteria(criteria);
	}
}
